$(function () {
    // 渲染左侧用户信息
    $.get("http://127.0.0.1:5000/admin", (data) => {
        console.log(data);
        $(".user_avatar img").attr("src", data[0].photo)
        $('.user_name').html(data[0].name)
        $('.four').html(data[1])
    })

    // 渲染全部文章
    let str = ''
    $.get("http://127.0.0.1:5000/blog/abstract", (data) => {
        console.log(data);
        data.forEach(ele => {
            if(ele.id % 2 === 0){
                str += `
                <a href="/blogWeb/details.html?id=${ele.id}">
            <li class="article lili">
                    <div class="img">
                        <img src="${ele.bgUrl}" alt="">
                    </div>
                    <div class="content">
                        <div class="title">${ele.title}</div>
                        <div class="date">
                            <img src="./img/iconfont/rili.png" alt="">
                            ${ele.publishTime}
                        </div>
                        <div class="text">${ele.abstract}</div>
                    </div>
                </li></a>`
            }else{
                str += ` <a href="/blogWeb/details.html?id=${ele.id}">
                <li class="article">
                        <div class="img">
                            <img src="${ele.bgUrl}" alt="">
                        </div>
                        <div class="content">
                            <div class="title">${ele.title}</div>
                            <div class="date">
                                <img src="./img/iconfont/rili.png" alt="">
                                ${ele.publishTime}
                            </div>
                            <div class="text">${ele.abstract}</div>
                        </div>
                    </li></a>`
            }
        });
        $('.ul').html(str)
    })
})